package com.easthome.util;

import lombok.Data;
import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author cxiaoy
 * @Date 2022/10/12 14:49
 */
@Data
public class MyDateConvert implements Converter<String, Date> {

    private String formatStr;

    @Override
    public Date convert(String dateStr) {
        if(dateStr==null || dateStr.equals("")){
            return null;
        }
        try {
            return new SimpleDateFormat(formatStr).parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
